﻿using FrameWorkSong;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PrefabsExamples : MonoBehaviourSimplify
{
    public override void OnBeforeDestroy() {}
    public Transform fa;
    Dictionary<string, Vector3> objPosDict = new Dictionary<string, Vector3>();

    SimpleObjectPool<PrefabsInfo> prefabsInfos;
    PrefabsCreate prefabsCreate;
    PrefabsCreate prefabsCreateUI;
    void mDestroy(PrefabsInfo obj)
    {
        obj = null;
    }
    private void Start()
    {

        //prefabsCreateUI = new PrefabsCreate(PrefabsType.UIImage, true,null);
        //prefabsCreate = new PrefabsCreate(PrefabsType.ObjCube,false,null);
        prefabsInfos = new SimpleObjectPool<PrefabsInfo>(() => new PrefabsInfo(), mDestroy, 0);
        Add();
        Debug.Log("第一步");
        Delay(2, () => {
            Debug.Log("第二步");
            ReleaseMemory();
            delete();
            Delay(2, () => {
                Debug.Log("第三步");

                Add2();
                Delay(2, () => {
                    Debug.Log("第四步");

                    retrun();
                    Delay(2, () => {
                        Debug.Log("deng");
                        ReleaseMemory();
                        Delay(2, () => {
                            Debug.Log("deng");
                            //ReleaseMemory();
                            Add3();
                        });
                    });
                });
            });
        });
    }
    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.A))
        {
            Add();
        }
        if (Input.GetKeyDown(KeyCode.B))
        {
            delete();
        }
        if (Input.GetKeyDown(KeyCode.C))
        {
            ReleaseMemory();
        }
    }
    
    
    void delete()
    {
        //List<string> names = new List<string>();
        //names.Add("One");
        //prefabsCreate.Remove(names);
        //removePre(fa.name, "Threea");
    }
    void Add()
    {
        //objPosDict.AddData("One", new Vector3(0, 0, 0));
        //objPosDict.AddData("Two", new Vector3(1, 0, 0));
        //objPosDict.AddData("Three", new Vector3(0, 1, 0));

        //prefabsCreate.Add(objPosDict);
        //prefabsCreateUI.Add(objPosDict);

        add(PrefabsType.ObjSphere, "Threea", new Vector3(0, 2, 0));
        add(PrefabsType.ObjCube, "Threea0", new Vector3(0, 1, 0));
        add("ObjSphere", "Threea1", new Vector3(0, 3, 0));

    }
    void add(PrefabsType prefabsType, string name, Vector3 vector3)
    {
        PrefabsInfo prefabsInfo = prefabsInfos.Allocate();
        prefabsInfo.PrefabsType = prefabsType;
        prefabsInfo.PrefabsName = name;
        prefabsInfo.PrefabsPos = vector3;
        prefabsInfo.IsUI = false;
        PrefabsManager.Instance.AddPrefabs(prefabsInfo, fa.transform);
        prefabsInfos.Recycle(prefabsInfo);
    }
    void add(string prefabsType, string name, Vector3 vector3)
    {
        PrefabsInfo prefabsInfo = prefabsInfos.Allocate();
        prefabsInfo.PrefabsTypeString = prefabsType;
        prefabsInfo.PrefabsName = name;
        prefabsInfo.PrefabsPos = vector3;
        prefabsInfo.IsUI = false;
        PrefabsManager.Instance.AddPrefabs(prefabsInfo, fa.transform);
        prefabsInfos.Recycle(prefabsInfo);
    }
    void removePre(PrefabsType prefabsType, string name)
    {
        PrefabsManager.Instance.RemovePrefabs(prefabsType, name);
    }

    void Add2()
    {
        //objPosDict.AddData("One", new Vector3(0, 0, 0));
        //objPosDict.AddData("Two", new Vector3(2, 0, 0));
        //objPosDict.AddData("Three", new Vector3(0, 2, 0));
        //objPosDict.AddData("Four", new Vector3(0, 3, 0));
        //prefabsCreate.Add(objPosDict);
        //prefabsCreateUI.Add(objPosDict);

        add(PrefabsType.ObjSphere, "Threea1", new Vector3(1, 3, 0));
    }
    void Add3()
    {
        add(PrefabsType.ObjSphere, "Threea2", new Vector3(0, 2, 0));
        add("ObjSphere", "Threea3", new Vector3(0, 3, 0));
        add(PrefabsType.ObjCube, "Threea", new Vector3(0, 2, 0));
    }
    void retrun()
    {
        //prefabsCreate.Remove();
        //prefabsCreateUI.Remove();
        //objPosDict.Clear();
        PrefabsManager.Instance.RemovePrefabs(PrefabsType.ObjCube);
    }
}
